package com.lrf.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lrf.eb.model.EbNews;
import com.lrf.eb.model.EbProduct;
import com.lrf.eb.model.EbProductCategory;
import com.lrf.eb.service.EbNewsService;
import com.lrf.eb.service.EbProductService;
import com.lrf.eb.service.EbproductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/front")
public class IndexController {
    @Autowired
    private EbProductService ebProductService;


    @Autowired
    private EbproductCategoryService ebproductCategoryService;

    @Autowired
    private EbNewsService ebNewsService;

    @RequestMapping("/index")
    public String index(Model model,
                        @RequestParam(value ="psize",defaultValue = "1")int psize,
                        @RequestParam(value = "pageSize",defaultValue = "8") int pageSize,
                        @RequestParam(value ="nsize",defaultValue = "1")int nsize,
                        @RequestParam(value = "newsSize",defaultValue = "8") int newsSize)
                        {
        System.out.println("======进入IndexController的index()方法=====");
        //TODO 1.查询商品表的数据
        Page<EbProduct> ebProductPage = ebProductService.page(psize,pageSize);
        //TODO 2.查询新闻表的数据
        Page<EbNews> ebNewsPage = ebNewsService.page(nsize,newsSize);
        //TODO 3.查询商品分类表数据
        Map<String,List<EbProductCategory>> cateMap =ebproductCategoryService.listCategory();

        //TODO 4.绑定数据到model---数据
        model.addAttribute("prodsPage",ebProductPage);//绑定商品信息
        model.addAttribute("cateMap",cateMap);//绑定商品分类信息
                            model.addAttribute("newsPage",ebNewsPage);//绑定新闻信息





        return "index";
    }
}
